def cals(g):
    if g == 1:return False
    chislo = True
    l = g - 1
    while l > 1:
        if not g % l:
            chislo = False
            break
        l-= 1
    return chislo

m = input()
if 10000 < int(m) < 999:
    r = []
    for i in range(len(m)):
        for l in range(i + 1, len(m) + 1):
            g = int(m[i:k])
            if isPrime(g):
                r += [g]
    print(max(r) if r else 0)

